%%%-------------------------------------------------------------------
%%% @author kk
%%% @copyright (C) 2024, <COMPANY>
%%% @doc
%%% 对数字列表进行求和再除以指定的参数，得到商和余数
%%% @end
%%% Created : 19. 7月 2024 11:02
%%%-------------------------------------------------------------------
-module(d4).
-author("kk").

%% API
-export([getShangAndYu/2,sum/1]).

%% 列表求和
sum([]) -> 0;
sum(List) -> sum(List, 0).
sum([], Count) -> Count;
sum([H | List], Sum) ->
  Count = H + Sum,
  sum(List, Count).


%% 列表求和再除以指定的参数，得到商和余数
getShangAndYu(X, Num) ->
  Sum = sum(X),
  {shang_and_yu, Sum / Num, Sum rem Num}.